#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans(1000000001),res;
int a[100001],b[100001],c[100001],f[100001],g[100001],id[100001];
pair<int,int> d[100001];
inline int read()
{
	int x(0);char ch(getchar());
	while(ch<48||ch>57) ch=getchar();
	while(ch>=48&&ch<=57) x=x*10+(ch^48),ch=getchar();
	return x;
}
signed main()
{
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) d[i].first=b[i]=read(),d[i].second=i;
	if(n<=100)
	{
		for(int i=1;i<=n;i++)
			for(int j=1;j<i;j++)
				for(int k=1;k<j;k++)
					ans=min(ans,a[i]+a[j]+a[k]+b[i]+b[j]+b[k]-min(b[i],min(b[j],b[k])));
		printf("%lld",ans);
		return 0;
	}
	sort(d+1,d+1+n);
	f[0]=g[0]=1000000001;
	for(int i=1;i<=n;i++) id[d[i].second]=i;
	for(int i=1;i<=n;i++) 
	{
		f[i]=min(f[i-1],a[d[i].second]);
	}
	for(int i=1;i<=n;i++)
	{
		c[i]=a[i]+b[i]+f[id[i]-1];
	}
	for(int i=1;i<=n;i++) 
	{
		g[i]=min(g[i-1],c[d[i].second]);
	}
	for(int i=1;i<=n;i++)
	{
		res=a[i]+b[i]+g[id[i]-1];
		ans=min(ans,res);
	}
	printf("%lld",ans);
	return 0;
}

